<template>
	<view class="mine">
		<titleName :name="name" :back-show="false" />
		<view class="top-img">
			<view class="my-msg">
				<image @click="updateAvator" :src="img" mode="">
				</image>
				<view class="msg">
					<view class="name">{{customername || parentdepartmentname}}</view>
					<view class="phone">{{ hbmobile || ''}}</view>
					<!-- 	<view class="name" v-if="admin">{{ departmentname || '无'}}</view>
					<view class="phone" v-if="admin">{{ mobile || '无'}}</view> -->
				</view>
			</view>
		</view>
		<view class="update-phone" style="margin-top: 30rpx;" @click="jumpUpdatePhone">
			<view class="left">
				<image class="icon" :src="resourceUrl+'phone.png'" mode="">
				</image>
				<text>更换手机号</text>
			</view>
			<image class="arrow"
				src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/right-arrow.png" mode="">
			</image>
		</view>
		<view class="update-phone" @click="jumpFeedBack" v-if="usertype==9">
			<view class="left">
				<image class="icon"
					src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/zhili.png" mode="">
				</image>
				<text>{{usertype==9?'个人信息':'意见反馈'}}</text>
			</view>
			<image class="arrow"
				src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/right-arrow.png" mode="">
			</image>
		</view>
		<!-- <view class="update-phone" @click="jumpSupervision" v-if="usertype==1">
			<view class="left">
				<image class="icon"
					src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/jianguanxinxi.png"
					mode="">
				</image>
				<text>监管信息</text>
			</view>
			<image class="arrow"
				src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/right-arrow.png" mode="">
			</image>
		</view> -->
		<view class="update-phone" @click="jumpMsgPublish" v-if="usertype==9">
			<view class="left">
				<image class="icon" :src="resourceUrl+'mime-publish.png'" mode="">
				</image>
				<!-- <image class="icon"
					src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/jianguanxinxi.png"
					mode="">
				</image> -->
				<text>信息发布</text>
			</view>
			<image class="arrow"
				src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/right-arrow.png" mode="">
			</image>
		</view>
		<view class="update-phone" @click="jumpMsgExamine" v-if="usertype==9">
			<view class="left">
				<image class="icon" :src="resourceUrl+'mine-shenpi.png'" mode="">
				</image>
				<text>审批</text>
			</view>
			<image class="arrow"
				src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/right-arrow.png" mode="">
			</image>
		</view>
		<view class="btn-wrap">
			<!-- <button @click="loginout">{{tokenFloag?'退出登录':'去登录'}}</button> -->
			<button @click="loginout">退出登录</button>
		</view>
	</view>
</template>

<script setup>
	import titleName from '../../components/titleName.vue'
	import uploadFile from '../../request/uploadFile.js'
	import http from '../../request/index.js'
	import {
		resourceUrl
	} from '../../request/config'
	import {
		onShow,
		onLoad
	} from '@dcloudio/uni-app'
	import {
		ref
	} from 'vue'
	let name = ref('我的')
	let usertype = ref('')
	let parentdepartmentname = ref('')
	let customername = ref('')
	let img = ref("https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/touxiang.png")
	let departmentname = ref('')
	let mobile = ref('')
	let admin = ref(false)
	let hbmobile = ref('')
	let tokenFloag = ref(false)
	let jumpMsgExamine = ()=>{
		uni.navigateTo({
			url:"/minePageOther/examine/index"
		})
	}
	let getAvator = () => {
		http({
			url: '/user/selfinfo',

		}).then((res) => {
			if (res.code == 0) {
				img.value = res.data.avatar ||
					'https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/touxiang.png'
				customername.value = res.data.customername
				hbmobile.value = res.data.mobile
				parentdepartmentname.value = res.data.parentdepartmentname
			}
		})
	}

	let updateAvator = () => {
		// if (!tokenFloag.value) return

		uni.chooseImage({
			sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
			count: 1,
			success: function(res) {
				let tempFilePaths = res.tempFilePaths

				for (var i = 0; i < tempFilePaths.length; i++) {
					uploadFile({
						filePath: tempFilePaths[i]
					}).then((result) => {

						if (result.code == 0) {
							http({
								url: '/user/changeavatar',
								data: {
									avatar: result.data.url
								}
							}).then((res) => {
								if (res.code == 0) {

									getAvator()
								}
							})
						}
					})
				}
			}
		});
	}
	onShow(() => {
		// admin.value = uni.getStorageSync('admin')
		// customername.value = uni.getStorageSync("customername1")
		// // console.log(customername.value, 'fds');
		// hbmobile.value = uni.getStorageSync("hbmobile")
		// departmentname.value = uni.getStorageSync("departmentname")
		// mobile.value = uni.getStorageSync("mobile")
		// uni.getStorageSync("TOKEN") ? tokenFloag.value = true : tokenFloag.value = false
		// if (tokenFloag.value) {

		// } else {
		// 	img.value = "https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/touxiang.png"
		// }
		usertype.value = uni.getStorageSync('usertype')
		getAvator()
	})

	let jumpUpdatePhone = () => {
		uni.navigateTo({
			url: "/minePageOther/updatephonenum/index"
		})
	}
	let jumpFeedBack = () => {
		if (usertype.value == 9) {
			uni.navigateTo({
				url: "/minePageOther/supervisioninformation/index"
			})
		} else {
			uni.navigateTo({
				url: "/minePageOther/feedback/index"
			})
		}
	}
	let jumpMsgPublish = () => {
		uni.navigateTo({
			url: "/minePageOther/msgpublish/index"
		})

	}
	let loginout = () => {
		// if (admin.value) {
		// 	let mobile = uni.getStorageSync('mobile') || ''
		// 	uni.clearStorageSync()
		// 	uni.setStorageSync('mobile', mobile)
		// } else {
		// 	uni.clearStorageSync()
		// }
		uni.navigateTo({
			url: "/pages/login/index"
		})

	}
	let jumpSupervision = () => {
		uni.navigateTo({
			url: "/minePageOther/supervisioninformation/index"
		})
	}
</script>

<style lang="scss" scoped>
	.mine {
		width: 100vw;
		height: 100vh;

		.btn-wrap {
			margin-top: 200rpx;
			padding: 0 39rpx;

			button {
				width: 100%;
				height: 88rpx;
				background: #0874FA;
				border-radius: 44rpx;
				line-height: 88upx;
				font-weight: 400;
				font-size: 34rpx;
				color: #FFFFFF;

			}
		}

		.update-phone {
			display: flex;
			align-items: center;
			padding-left: 40rpx;
			padding-right: 40rpx;
			justify-content: space-between;
			height: 134rpx;
			border-bottom: 2rpx solid #F3F5F7;

			.left {
				display: flex;
				align-items: center;

				.icon {
					width: 54rpx;
					height: 54rpx;
				}

				text {
					margin-left: 23rpx;
					font-weight: 500;
					font-size: 31rpx;
					color: #000000;

				}
			}

			.arrow {
				width: 15rpx;
				height: 25rpx;
				margin-left: 426rpx;
			}
		}

		.top-img {
			width: 100vw;
			height: 201rpx;
			background: url("https://splendid.oss-cn-beijing.aliyuncs.com/static/greenenterprise/mine-bgc.png") no-repeat;
			background-size: 100% 100%;
			padding-top: 22rpx;
			padding-left: 43rpx;
			position: relative;



			.my-msg {
				display: flex;

				image {
					width: 95rpx;
					height: 95rpx;
					border-radius: 50%;
				}

				.msg {
					display: flex;
					flex-direction: column;
					margin-left: 24rpx;
					justify-content: space-between;
					padding: 6rpx 0;

					.name {

						font-weight: 500;
						font-size: 36rpx;
						color: #FFFFFF;

						font-family: Source Han Sans CN;



					}

					.phone {

						font-weight: 600;
						font-size: 23rpx;
						color: #FFFFFF;

					}
				}
			}
		}
	}
</style>